namespace Pp.UI.Models
{
    using System;
    using System.Web;
    using System.IO;
    using System.Web.Hosting;
    using Core;

    internal class DiskFileStore : IFileStore
    {
        private readonly string _uploadsFolder = HostingEnvironment.MapPath("~/Content/LinkItems/");

        public Result<Guid> SaveUploadedFile(HttpPostedFileBase fileBase)
        {
            var identifier = Guid.NewGuid();
            fileBase.SaveAs(GetDiskLocation(identifier));
            return Result<Guid>.AsSuccess(identifier);
        }

        private string GetDiskLocation(Guid identifier)
        {
            return Path.Combine(_uploadsFolder, identifier.ToString());
        }
    }
}